package com.yuan;

/**
 * @ClassName: test2
 * @Description: TODO
 * @Author MrYuan
 * @Date: 2021/3/2 14:00
 * @Version 1.0
 */
public class test2 {
    public static void main(String[] args) {
        String s1 = "abc";
        String s2 = "bc";
        System.out.println(match(s1, s2));
    }

    public static int match(String st1, String st2) {
        int s1 = st1.length();
        int s2 = st2.length();
        int i = 0;
        int j = 0;

        while (i < s1 && j < s2) {
            if (st1.charAt(i) == st2.charAt(j)) {
                i++;
                j++;
            } else {
                i = i - (j - 1);
                j = 0;
            }
        }
        if (j == s2) {
            return s1-j;
        }

        return -1;
    }
    public int[] kmpNext(String str){
        int[] next = new int[str.length()];

        return next;
    }

}